<?php

class LocationImpressionAction extends CommonAction {
public function index(){
$sid = intval($_REQUEST['supplier_location_id']);
if($sid == 0) die();
$page_idx = intval($_REQUEST['p'])==0?1:intval($_REQUEST['p']);
$page_size = C('PAGE_LISTROWS');
$limit = (($page_idx-1)*$page_size).','.$page_size;
if (isset ( $_REQUEST ['_order'] )) {
$order = $_REQUEST ['_order'];
}
if (isset ( $_REQUEST ['_sort'] )) {
$sort = $_REQUEST ['_sort'] ?'asc': 'desc';
}else {
$sort = $asc ?'asc': 'desc';
}
if($order!='sort')
{
$orderby = '';
}
else
{
$orderby = 'order by '.$order.' '.$sort;
}
if(trim($_REQUEST['name'])!='')
{
$list = $GLOBALS['db']->getAll('select id,sid,name,uid,number_count from '.DB_PREFIX.'location_impression where sid='.$sid." AND name like '%".trim($_REQUEST['name'])."%'  $orderby limit ".$limit);
$total = $GLOBALS['db']->getOne('select count(*) from '.DB_PREFIX.'location_impression where sid='.$sid." AND name like '%".trim($_REQUEST['name'])."%'");
}
else
{
$list= $GLOBALS['db']->getAll('select id,sid,name,uid,number_count from '.DB_PREFIX.'location_impression where sid='.$sid." $orderby limit ".$limit);
$total = $GLOBALS['db']->getOne('select count(*) from '.DB_PREFIX.'location_impression where sid='.$sid.' ');
}
$p = new Page ( $total,'');
$page = $p->show ();
$sortImg = $sort;
$sortAlt = $sort == 'desc'?l('ASC_SORT') : l('DESC_SORT');
$sort = $sort == 'desc'?1 : 0;
$this->assign ( 'sort',$sort );
$this->assign ( 'order',$order );
$this->assign ( 'sortImg',$sortImg );
$this->assign ( 'sortType',$sortAlt );
$this->assign ( 'list',$list );
$this->assign ( 'page',$page );
$this->assign ( 'nowPage',$p->nowPage);
$this->display ();
}
public function foreverdelete() {
$ajax = intval($_REQUEST['ajax']);
$id = $_REQUEST['id'];
if (!empty ($id)) {
$name = $this->getActionName();
$model = D($name);
$pk = $model->getPk();
$ids = explode(',',$id);
$condition = array (
$pk =>array (
'in',
$ids
)
);
$list = $model->where($condition)->findAll();
if (false !== $model->where($condition)->delete()) {
foreach ($list as $k =>$v) {
$sids[$v['sid']]['id'] = $v['sid'];
}
foreach($sids as $kk=>$vv){
syn_supplier_locationcount($vv['id']);
}
save_log($ids .l('FOREVER_DELETE_SUCCESS'),1);
$this->success(l('FOREVER_DELETE_SUCCESS'),$ajax);
}else {
save_log($ids .l('FOREVER_DELETE_FAILED'),0);
$this->error(l('FOREVER_DELETE_FAILED'),$ajax);
}
}else {
$this->error(l('INVALID_OPERATION'),$ajax);
}
}
}
function getUNAME($id) {
if ($id == 0)
return '';
else
return M('User')->where('id='.$id)->getField('user_name');
}
function getMerchant($id) {
return M('SupplierLocation')->where('id='.$id)->getField('name');
}
?>